package editer;

import haxe.ui.backend.html5.HtmlUtils;
import js.Browser;
import js.html.IFrameElement;
import haxe.ui.containers.Box;

/**
 * WebView支持iframe
 */
class IFrameView extends Box {
	/**
	 * WebView控制器
	 */
	private var _iframe:IFrameElement = null;

	/**
	 * 获得IFrame框架对象
	 * @return IFrameElement
	 */
	public function getIFrame():IFrameElement {
		return this._iframe;
	}

	public function new() {
		super();
		_iframe = Browser.document.createIFrameElement();
		_iframe.frameBorder = "none";
		this.element.append(_iframe);
	}

	public var url(get, set):String;

	private function get_url():String {
		return _iframe.src;
	}

	private function set_url(value:String):String {
		_iframe.src = value;
		return value;
	}

	private override function validateComponentLayout():Bool {
		var b = super.validateComponentLayout();
		if (width > 0 && height > 0) {
			_iframe.width = HtmlUtils.px(width);
			_iframe.height = HtmlUtils.px(height);
		}
		return b;
	}
}
